package com.xinmao.quantitative.trad.strategies.combine;

import com.xinmao.quantitative.trad.strategies.IStrategy;
import org.springframework.stereotype.Component;
import org.ta4j.core.BarSeries;
import org.ta4j.core.BaseStrategy;
import org.ta4j.core.Rule;
import org.ta4j.core.Strategy;
import org.ta4j.core.indicators.PPOIndicator;
import org.ta4j.core.indicators.helpers.ClosePriceIndicator;
import org.ta4j.core.num.DecimalNum;
import org.ta4j.core.num.Num;
import org.ta4j.core.rules.OverIndicatorRule;
import org.ta4j.core.rules.UnderIndicatorRule;

@Component
public class TrendCompositeStrategy implements IStrategy {

    @Override
    public Strategy buildStrategy(BarSeries series){

        ClosePriceIndicator closePrice = new ClosePriceIndicator(series);
        PPOIndicator shortPPO = new PPOIndicator(closePrice, 5, 10);
        PPOIndicator longPPO = new PPOIndicator(closePrice, 20, 40);
        PPOIndicator veryLongPPO = new PPOIndicator(closePrice, 60, 120);



        // Entry rule
        Rule buy = new OverIndicatorRule(shortPPO, 0)
                .and(new OverIndicatorRule(longPPO, 0))
                .and(new OverIndicatorRule(veryLongPPO, 0));

        // Exit rule
        Rule sell = new UnderIndicatorRule(shortPPO, 0);


        return new BaseStrategy(buy, sell);
    }

    @Override
    public Num getScore() {
        return DecimalNum.valueOf(1);
    }
}
